package com.wxzz.elearing.evaluation.api.app;

import com.alibaba.fastjson.JSONObject;
import com.wxzz.elearing.evaluation.dto.BusinessCategoryEvaluationHistoryDto;
import com.wxzz.elearing.evaluation.dto.EvaluationCriterionDto;
import com.wxzz.elearing.evaluation.entity.BusinessCategoryEvaluationHistory;
import com.wxzz.elearing.evaluation.entity.EvaluationCriterion;
import com.wxzz.elearing.evaluation.service.IBusinessCategoryEvaluationService;
import com.wxzz.elearing.evaluation.service.IBusinessCategoryRuleService;
import com.wxzz.elearning.common.vo.JgPageVo;
import com.wxzz.elearning.common.vo.ReturnVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/wx-business-category-evaluation")
@Api(tags = "能力测评接口(小程序)")
public class WxBusinessCategoryEvaluationController {

    @Autowired
    private IBusinessCategoryEvaluationService businessCategoryEvaluationService;

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @ApiOperation(value = "列出个人能力测评记录(小程序)", notes = "列出个人能力测评记录(小程序)", httpMethod = "POST", tags = "小程序")
    @RequestMapping(value = "listBusinessCategoryEvaluationHistory", method = RequestMethod.POST)
    public ReturnVO<JgPageVo<List<BusinessCategoryEvaluationHistory>>> listBusinessCategoryEvaluationHistory(@RequestHeader String token, @Valid @RequestBody BusinessCategoryEvaluationHistoryDto businessCategoryEvaluationHistoryDto) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        businessCategoryEvaluationHistoryDto.setWxUserId(jsonObject.getLong("id"));
        return businessCategoryEvaluationService.listBusinessCategoryEvaluationHistory(businessCategoryEvaluationHistoryDto);
    }

    @ApiOperation(value = "列出企业能力测评记录(小程序)", notes = "列出企业能力测评记录(小程序)", httpMethod = "POST", tags = "小程序")
    @RequestMapping(value = "listBusinessCategoryEvaluationHistory4enterprise", method = RequestMethod.POST)
    public ReturnVO<JgPageVo<List<BusinessCategoryEvaluationHistory>>> listBusinessCategoryEvaluationHistory4enterprise(@RequestHeader String token, @Valid @RequestBody BusinessCategoryEvaluationHistoryDto businessCategoryEvaluationHistoryDto) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        businessCategoryEvaluationHistoryDto.setEnterpriseId(jsonObject.getLong("enterpriseId"));
        return businessCategoryEvaluationService.listBusinessCategoryEvaluationHistory(businessCategoryEvaluationHistoryDto);
    }


}
